package com.sm.controller;

import com.github.pagehelper.PageInfo;
import com.sm.entity.ResultMap;
import com.sm.entity.UserInfo;
import com.sm.service.PersonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/admin/person")
public class PersonController {

    @Autowired
    ResultMap resultMap;
    @Autowired
    PersonService personService;

    @ResponseBody
    @RequestMapping("/informaluser")
    public ResultMap informalUser()throws Exception{
        List<UserInfo> users = personService.informalUser();
        PageInfo<UserInfo> result = new PageInfo<UserInfo>(users);
        resultMap.setResult("result",result);
        return resultMap;
    }

    @ResponseBody
    @RequestMapping("/informaluser.do")
    public ResultMap informalUserDo(Integer uid)throws Exception{
        personService.formalUser(uid);
        resultMap.setMessage("转正成功");
        return resultMap;
    }

    @ResponseBody
    @RequestMapping("/searchuser")
    public ResultMap searchUser(String name)throws Exception{
        System.out.println(name);
        List<UserInfo> list = personService.searchUser(name);
        resultMap.setResult("users",list);
        return resultMap;
    }
}
